<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('posts')) {
            Schema::create('posts', function (Blueprint $table) {
                $table->engine = 'InnoDB';
                $table->bigIncrements('id');
                $table->string('title', 100)->default('测试')->comment('标题');
                $table->text('content')->comment('详情');
                $table->bigInteger('user_id')->default(0)->comment('用户表外键');
                $table->integer('created_at')->default(0)->comment('创建时间');
                $table->integer('updated_at')->default(0)->comment('修改时间');
                $table->index('title');
                $table->index('user_id');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
